<template>
	<el-dialog v-model="isShow" :title="title" width="300px" :before-close="handleClose" custom-class="publicDialog">
		<el-input class="a-input" v-model="code"></el-input>
		<div style="display: flex; justify-content: center; margin-top: 16px">
			<el-button @click="exchangeCard" type="primary">兑换</el-button>
		</div>
	</el-dialog>
</template>
<script setup>
import { ref, defineExpose, getCurrentInstance, defineEmits } from 'vue'
import {cardExchange} from '@/api'
import { useRoute, useRouter } from 'vue-router'
import { useAuth } from '@/hooks'
const router = useRouter()
const props = defineProps({
	title: {
		type: String,
		default: '卡密兑换'
	}
})
const emits = defineEmits(['getData'])
const code = ref('')
const isShow = ref(false)
const show = (val) => {
	isShow.value = true
	code.value = ''
}
const exchangeCard = async () => {
	const r = await cardExchange({
		code: code.value
	})
	if (r) {
		isShow.value = false
		ElMessage.success('兑换成功')
		router.go()
		// emits('getData')
	}
}
defineExpose({
	show
})
</script>
